

# A2a_plot_export_prices
#===============================================================================
  
# Description: This file plots average export prices for each country and creates 
# one of the Figure 1 subplots

rm(list = ls())

setwd("D:/data_replication")

library("data.table")  
library("ggplot2")  
library("ggrepel")  
library("stargazer")  

output <- fread('statistics_and_graphs/export_prices/output_files/prices_exporter.txt')
output[ , V1 := gsub("s", "", V1)]
output <- output[V1 != ""]
output <- output[V1 != "_con"]
setnames(output, "V1", "partner")
output[ , partner := as.numeric(partner)]
setnames(output, "V2", "price")
output[ , price := as.numeric(price)]

gdp_data <- fread('data/gdp_per_capita/gdp_per_capita_defl.csv')
gdp_data <- gdp_data[year == 2007]

output <- merge(output, gdp_data, by = "partner")
output <- as.data.table(output)

iso3 <- fread('data/country_codes/ISO3_partner_codes.csv') 
output <- merge(output, iso3, by = "partner")
output <- as.data.table(output)

output[ , gdp_log := log(gdp_per_capita_defl)]
output <- output[ISO3 != "FSM"]

plot_export_prices <- ggplot(output, aes(x=gdp_log, y=price)) +
                geom_text(label=output$ISO3, size = 5) +
                theme(text = element_text(size=17)) +
                geom_smooth(method=lm) +
                labs(x = "Exporter GDP per capita (in logs)", y = "Avg. Export Price") +
                theme(axis.title=element_text(size=30)) +
                theme(axis.text=element_text(size=18))

ggsave("statistics_and_graphs/export_prices/plot_export_prices.png", plot = plot_export_prices, width = 12, height = 9)


